using System;
using RayDen.Library.Core.Primitives;

namespace RayDen.Library.Components.Color
{
    public class RgbRadiance : RadianceEvaluationBase<RgbSpectrum>
    {
        public static RgbRadiance Zero = new RgbRadiance(RgbSpectrum.ZeroSpectrum());
        public static RgbRadiance Unit = new RgbRadiance(RgbSpectrum.UnitSpectrum());

        public RgbRadiance(ref RgbSpectrum spc)
            : base(ref spc)
        {
        }

        public RgbRadiance(RgbSpectrum spc)
            : base(spc)
        {
        }

        public RgbRadiance(RadianceEvaluationBase<RgbSpectrum> val)
            : base(val)
        {
        }

        public override IRadianceEvaluation Mul(float value)
        {
            this.Spectra.Mul(value);
            return this;
        }

        public override IRadianceEvaluation Add(float value)
        {
            this.Spectra.Add(value);
            return this;
        }

        public override IRadianceEvaluation Div(float value)
        {
            this.Spectra.Div(value);
            return this;
        }

        public override void ToRgbSpectrum(out RgbSpectrum result)
        {
            result = this.Spectra;
        }

        public override float[] ToArray()
        {
            return this.Spectra.ToArray();
        }

        protected override RadianceEvaluationBase<RgbSpectrum> Multiply(RadianceEvaluationBase<RgbSpectrum> val)
        {
            val.Spectra.Mul(ref val.Spectra);
            return this;
        }

        protected override RadianceEvaluationBase<RgbSpectrum> Add(RadianceEvaluationBase<RgbSpectrum> val)
        {
            val.Spectra.Add(ref val.Spectra);
            return this;
        }

        public override bool IsBlack
        {
            get { return this.Spectra.IsBlack(); }
            protected set { throw new NotImplementedException(); }
        }

        protected override IRadianceEvaluation Convert(IRadianceEvaluation val)
        {
            if (val is FloatRadiance)
            {
                var value = (val as FloatRadiance);
                return new RgbRadiance(new RgbSpectrum(value.Spectra));

            }
            else if (val is SpectralRadiance)
            {
                var value = (val as SpectralRadiance);
                return new RgbRadiance(value.Spectra.ToRgb());
            }
            return val;
        }
        public override IRadianceEvaluation Clone()
        {
            return new RgbRadiance(this);
        }
    }
}